package logic

import (
	"context"
	"house_srv/models"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseAddLogic) HouseAdd(in *house.HouseAddRequest) (*house.HouseAddResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var h models.House
	h.Title = in.Title
	h.UserId = int(in.UserId)
	h.Area = int(in.Area)
	h.HouseStatus = int(in.HouseStatus)
	h.Price = float64(in.Price)
	h.Address = in.Address
	if err = h.Create(); err != nil {
		logx.Error("房源发布失败", err)
		return nil, err
	}
	return &house.HouseAddResponse{
		HouseId: int64(h.ID),
	}, nil
}
